#!/bin/bash

plugins_path=~/.oh-my-zsh/custom/plugins
echo -e '\033[1;32m 安装zsh-syntax-highlighting:模仿fish命令行高亮的插件  \033[0m'
if [[ -d ${plugins_path}/zsh-syntax-highlighting ]];then
    echo "" > /dev/null
else
    git clone https://gitee.com/twd2606/zsh-syntax-highlighting.git "${plugins_path}"/zsh-syntax-highlighting
fi

echo -e '\033[1;32m 安装zsh-autosuggestions:根据命令历史记录自动推荐和提示的插件  \033[0m'
if [[ -d ${plugins_path}/zsh-autosuggestions ]];then
    echo "" > /dev/null
else
    git clone https://gitee.com/twd2606/zsh-autosuggestions.git "${plugins_path}"/zsh-autosuggestions
fi

echo -e '\033[1;32m 安装zsh-completions:自动命令补全，类似bash-completions功能的插件 \033[0m'
if [[ -d ${plugins_path}/zsh-completions ]];then
    echo "" > /dev/null
else
    git clone https://gitee.com/twd2606/zsh-completions "${plugins_path}"/zsh-completions
fi

echo -e '\033[1;32m 安装history-substring-search:按住向上箭头可以搜索出现过该关键字的历史命令插件 \033[0m'
if [[ -d ${plugins_path}/zsh-history-substring-search ]];then
    echo "" > /dev/null
else
    git clone https://gitee.com/mirrors_zsh-users/zsh-history-substring-search.git "${plugins_path}"/zsh-history-substring-search
fi

echo -e '\033[1;32m 安装history-search-multi-word:ctrl+r搜索历史记录插件 \033[0m'
if [[ -d ${plugins_path}/history-search-multi-word ]];then
    echo "" > /dev/null
else
    #git clone https://github.com/z-shell/H-S-MW.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/H-S-MW
    git clone https://gitee.com/mirrors_zdharma/history-search-multi-word.git "${plugins_path}"/H-S-MW
fi

echo -e '\033[1;32m 配置zsh加载的插件 \033[0m'
sed -ie "/^plugins=(git)/d" ~/.zshrc
sed -ie "/^source/d" ~/.zshrc
cat <<EOF >> ~/.zshrc
plugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
  zsh-completions
  z
  history-substring-search
  command-not-found
  colored-man-pages
  extract
  H-S-MW
)
source $ZSH/oh-my-zsh.sh
EOF

echo -e '\033[1;32m 重启终端生效 \033[0m'
exit